package com.example.config;

import com.example.iterceptor.HandleInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.PathMatcher;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;

@Configuration
public class Interceptor implements WebMvcConfigurer {
    @Autowired
    private HandleInterceptor handleInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(handleInterceptor)
                // /**: 拦截所有请求 /*: 拦截一级路径下的所有请求 例如: 能匹配/user,/login 不能匹配/user/login
                // /user/*: 拦截/user下的所有请求 例如: 能匹配/user/login 不能匹配/user,/user/login/1
                // /user/**: 拦截/user下的所有请求 例如: 能匹配/user/login 能匹配/user/login/1
                .addPathPatterns("/**")
                .excludePathPatterns("/login")//不拦截
                .order(1);//优先级
//                .pathMatcher(new PathMatcher())//匹配器
    }

}
